package com.jiefeng.manage.web.controller;

import com.jiefeng.manager.page.PageParam;
import com.jiefeng.manager.queryRequest.RefundOrderRequest;
import com.jiefeng.manager.service.RefundService;
import com.jiefeng.manager.table.OrderInfo;
import com.jiefeng.manager.table.RefundOrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by yusong on 16-1-5.
 * 说明：测试web接收类
 */
@Controller
public class RefundCtrl {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private RefundService refundService;

    /*
    * 首页
    * */
    @RequestMapping(value = "/refund/list")
    public String list(@ModelAttribute("pageParam") RefundOrderRequest param) {
        //分页
        int pageStartNum = 0;
        //分页计算
        pageStartNum = (param.getPageNum() - 1) * param.getPageSize();
        String page = " limit " + String.valueOf(pageStartNum) + "," + String.valueOf(param.getPageSize());
        param.setPage(page);
        try {
            List<RefundOrderInfo> refunList = refundService.getListBypage(param);
            param.setTotalCount(refundService.getCount(param));
            request.setAttribute("pageParam", param);
            request.setAttribute("refunList", refunList);
        } catch (java.lang.Exception exception) {
            exception.printStackTrace();
        }
        return "/jiefeng/pay/refund";
    }

    /*
    * ajax
    * 按照退款订单id查询查询
    * */
    @RequestMapping("/queryRefundById/{refundOrderId}")
    @ResponseBody
    public List<RefundOrderInfo> query(@PathVariable("refundOrderId") String orderId) {
        List<RefundOrderInfo> refundOrderInfo = refundService.getOrderListById(orderId);
        return refundOrderInfo;
    }

    /*
 * ajax
 * 按照页面条件查询
 * */
    @RequestMapping("/queryRefundByOrder")
    @ResponseBody
    public List<RefundOrderInfo> queryByParm(@RequestBody RefundOrderRequest request) {
        List<RefundOrderInfo> refundOrderInfo = refundService.getOrderListByRequest(request);
        return refundOrderInfo;
    }
    /**
     * ajax
     * 按照退款订单id查询查询
     * */
    @RequestMapping("/queryRefundDetail/{orderId}")
    public String queryByid(@PathVariable("orderId") String orderId) {
        List<RefundOrderInfo> orderInfoList = refundService.getOrderListById(orderId);
        RefundOrderInfo orderInfo=orderInfoList.size()>0?orderInfoList.get(0):new RefundOrderInfo();
        request.setAttribute("orderInfo", orderInfo);
        return "/jiefeng/pay/refundDetail";
    }



}
